let request = 'http://localhost:8080/';
let ID = window.sessionStorage.getItem('courseID');
let currentCourseId = window.sessionStorage.getItem('currentCourseId');
layui.use('table', function () {
    const table = layui.table;
    table.render({
        elem: '#courseChoose'
        , url: request + '/course/query/' + ID //数据接口
        , request: {
            pageName: 'page' //页码的参数名称，默认：page
            , limitName: 'pageSize' //每页数据量的参数名，默认：limit
        }
        , parseData: function (res) {
            return {
                "code": res.code, //解析接口状态
                "msg": res.msg, //解析提示文本
                "count": res.data.total, //解析数据长度
                "data": changeNature(res.data.data) //解析数据列表
            }
        }
        , title: '课程信息表'
        , cols: [[
            {field: 'id', title: 'ID', width: 100}
            , {field: 'courseId', title: '课程号', width: 200}
            , {field: 'courseName', title: '课程名', width: 120}
            , {field: 'teacherId', title: '教师编号', width: 150}
            , {field: 'collegeId', title: '学院', width: 100}
            , {field: 'systemId', title: '系', width: 100}
            , {field: 'credit', title: '学分', width: 60}
            , {field: 'nature', title: '课程属性', width: 100}
            , {field: 'number', title: '可选人数', width: 90}
            , {field: 'restNumber', title: '剩余可选人数', width: 100}
        ]]
        , page: false
    })
    table.render({
        elem: '#courseStudent'
        , height: 'full'
        , url: request + '/course/student/list/'  //数据接口
        , parseData: function (res) {
            return {
                "code": res.code, //解析接口状态
                "msg": res.msg, //解析提示文本
                "count": res.data.total, //解析数据长度
                "data": changeNature(res.data.data) //解析数据列表
            }
        }
        , request: {
            courseId: 'courseId'
            , pageName: 'page' //页码的参数名称，默认：page
            , limitName: 'pageSize' //每页数据量的参数名，默认：limit
        }
        , where: {
            courseId: currentCourseId
        }
        , title: '已选学生信息表'
        , cols: [[
            {field: 'id', title: 'ID', width: 80}
            , {field: 'studentId', title: '学号', width: 100}
            , {field: 'claId', title: '班级', width: 80}
            , {field: 'name', title: '姓名', width: 120}
            , {field: 'gender', title: '性别', width: 80}
            , {field: 'email', title: '邮箱', width: 250}
            , {field: 'phone', title: '电话', width: 200}
            , {field: 'collegeId', title: '学院', width: 100}
            , {field: 'systemId', title: '系', width: 100}
        ]]
        , page: true
    });

    function changeNature(courses) {
        for (let course of courses) {
            course.nature = '选修课';
        }
        return courses;
    }
})